package com.example.controller.shopping;

import com.example.common.Result;

import com.example.model.dto.HospitalDto;
import com.example.model.dto.MedicinesDto;
import com.example.model.entity.shopping.Medicines;
import com.example.model.vo.MedicinesVO;
import com.example.service.shopping.MedicinesService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 药品信息表前端操作接口
 **/
@RestController
@RequestMapping("/medicines")
@Api(tags = "药品信息接口")
public class MedicinesController {

    @Resource
    private MedicinesService medicinesService;

    /**
     * 查询所有状态为可售的药物信息并按销量从高到底排序
     * 查询分类ID名称，销售商家名称
     * 查询商品规格样式对应信息
     */
    @ApiOperation(value = "查询所有药品详细信息")
    @GetMapping("/selectAll")
    public Result selectAll(Medicines medicines) {
        List<MedicinesVO> medicinesVOList= medicinesService.selectAll(medicines);
        return Result.success(medicinesVOList);
    }

    /**
     * 根据分类ID查询销量靠前状态为可售的药物信息
     */
    @ApiOperation(value = "根据分类ID查询")
    @GetMapping("/selectByTypeId")
    public Result selectByType(@RequestParam Integer typeId) {
        List<MedicinesVO> medicines = medicinesService.selectByTypeId(typeId);
        return Result.success(medicines);
    }



    /**
     * 根据分类名称查询销量靠前状态为可售的药物信息
     */
    @ApiOperation(value = "根据分类名称查询")
    @GetMapping("/selectByTypeName")
    public Result selectByType(@RequestParam String typeName) {
        List<MedicinesVO> medicines = medicinesService.selectByTypeName(typeName);
        return Result.success(medicines);
    }

    /**
     * 根据ID查询药物详细信息
     * 查询分类ID名称，销售商家名称
     * 查询商品规格样式对应信息
     */
    @ApiOperation(value = "根据ID查询药品详细信息")
    @GetMapping("/selectDetailById/{medicinesId}")
    public Result selectDetailById(@PathVariable Integer medicinesId) {
        MedicinesVO medicinesVo = medicinesService.selectDetailById(medicinesId);
        return Result.success(medicinesVo);
    }


    @GetMapping("/selectByBusinessId")
    public Result selectByBusinessId(@RequestParam Integer businessId) {
        List<MedicinesVO> medicinesVoList = medicinesService.selectByBusinessId(businessId);
        return Result.success(medicinesVoList);
    }

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Medicines medicines = medicinesService.selectById(id);
        return Result.success(medicines);
    }
    @GetMapping("/selectMedicinesByName/{name}")
    public Result selectMedicinesByName(@PathVariable String name) {
        Integer medicinesId = medicinesService.selectMedicinesByName(name);
        return Result.success(medicinesId);
    }
    /**
     * 新增
     */
    @ApiOperation(value = "新增药品信息")
    @PostMapping("/add")
    public Result add(@RequestBody Medicines medicines) {
        medicinesService.add(medicines);
        return Result.success();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除药品信息")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        medicinesService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @ApiOperation(value = "批量删除药品信息")
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        medicinesService.deleteBatch(ids);
        return Result.success();
    }
    /**
     * 批量修改
     */
    @ApiIgnore
    @PutMapping("/updateBatch")
    public Result updateBatch(@RequestBody MedicinesDto medicinesDto) {
        medicinesService.updateBatch(medicinesDto);
        return Result.success();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改药品信息")
    @PutMapping("/update")
    public Result updateById(@RequestBody Medicines medicines) {
        medicinesService.updateById(medicines);
        return Result.success();
    }

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询药品信息")
    @GetMapping("/selectPage")
    public Result selectPage(Medicines medicines,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Medicines> page = medicinesService.selectPage(medicines, pageNum, pageSize);
        return Result.success(page);
    }

}
